package synchroniztion;

/**
 * @program: Dome
 * @description:
 * @className: Baoaipu
 * @author: rjt99999
 * @version: 1.0.0
 * @create: 2020-08-03 09:50
 **/


public class Baoaipu extends Thread {


    //制造包子
    private Baozi baozi;

    public Baoaipu(String name, Baozi baozi) {
        super(name);
        this.baozi = baozi;
    }

    @Override
    public void run() {


        int count = 0;


        while (true) {
            synchronized (baozi) {

                if (baozi.flag == true) {


                    try {


                        //有包子 线程等待
                        baozi.wait();


                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }


                }

                System.out.println("meiyou,开始做");

                count++;


                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("已做好");


                baozi.flag = true;

                baozi.notify();
            }
        }


    }


}
